package com.hmdp.controller;


import com.hmdp.dto.Result;
import com.hmdp.entity.Voucher;
import com.hmdp.service.IVoucherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 豪哥
 */
@Api(tags = "优惠券相关接口")
@RestController
@RequestMapping("/voucher")
public class VoucherController {

    @Resource
    private IVoucherService voucherService;

    @ApiOperation(value = "新增秒杀券", notes = "添加一个新的秒杀优惠券")
    @ApiImplicitParam(name = "voucher", value = "优惠券信息，包含秒杀信息", required = true, dataType = "Voucher")
    @PostMapping("seckill")
    public Result addSeckillVoucher(@RequestBody Voucher voucher) {
        voucherService.addSeckillVoucher(voucher);
        return Result.ok(voucher.getId());
    }

    @ApiOperation(value = "新增普通券", notes = "添加一个新的普通优惠券")
    @ApiImplicitParam(name = "voucher", value = "优惠券信息", required = true, dataType = "Voucher")
    @PostMapping
    public Result addVoucher(@RequestBody Voucher voucher) {
        voucherService.save(voucher);
        return Result.ok(voucher.getId());
    }

    @ApiOperation(value = "查询店铺优惠券", notes = "查询指定店铺的优惠券列表")
    @ApiImplicitParam(name = "shopId", value = "店铺id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/list/{shopId}")
    public Result queryVoucherOfShop(@PathVariable("shopId") Long shopId) {
        return voucherService.queryVoucherOfShop(shopId);
    }
}
